<template>
  <view v-if="visible" class="loading-spinner">
    <view class="spinner" :class="{ large: size === 'large' }"></view>
    <text v-if="text" class="loading-text">{{ text }}</text>
  </view>
</template>

<script setup lang="ts">
  interface Props {
    visible?: boolean;
    size?: 'small' | 'large';
    text?: string;
  }

  withDefaults(defineProps<Props>(), {
    visible: true,
    size: 'small',
    text: '',
  });
</script>

<style lang="scss" scoped>
  .loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16rpx;
  }

  .spinner {
    width: 32rpx;
    height: 32rpx;
    border: 3rpx solid #f3f3f3;
    border-top: 3rpx solid #007aff;
    border-radius: 50%;
    animation: spin 1s linear infinite;

    &.large {
      width: 48rpx;
      height: 48rpx;
      border-width: 4rpx;
    }
  }

  .loading-text {
    font-size: 24rpx;
    color: #666;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
</style>
